<div class="contextual">
  <%= link_to_csv_export(@timesheet) %>
  <%= permalink_to_timesheet(@timesheet) %>
</div>

<h2><%= l(:timesheet_title)%></h2>

<%= render :partial => 'form' %>

<%= call_hook(:plugin_timesheet_views_timesheets_report_before_time_entries, { :timesheet => @timesheet }) %>

<%= form_tag({}, { :id => 'time_entries'}) do -%>
  <% if @timesheet.time_entries.length > 0 %>
    <h2><%= l(:label_spent_time) %> (<%= h(number_with_precision(@grand_total, :precision => @precision)) -%> <%= h(l(:field_hours)) -%>)</h2>
    <% puts  @timesheet.time_entries.to_yaml %>
    <% @timesheet.time_entries.each do |entryname,entry|
      case @timesheet.sort
        when :user %>
        <h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
        <%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
      <% when :issue %>
        <h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
        <%= render :partial => 'by_issue', :locals => {:entry => entry, :name => entryname, :total => 0 } %>
      <% when :group %>
        <h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>
        <%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
      <% when :date %>
        <%#*entry[:logs].each do |log|%>
        <% logger.debug "#{'*'*100}\n ENTRYNAME > #{entryname.to_yaml} ENTRY #{entry[:logs][0].id}\n#{'*'*100}"%> 

        <h3><%= toggle_issue_arrows_date(entryname) %><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>)</h3>

        <span class="<%= cycle("odd", "even") %> issue-time-entry-<%= entryname -%>" style="display:none;">
          <%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>
        </span> 

        <%#*end%>
        <script type="text/javascript">
          function toggleTimeEntriesdate(entryname) {

            $('.issue-time-entry-' + entryname).each(function() {
              $(this).toggle();
            })
            $('.toggle-' + entryname).each(function() {
              $(this).toggle();
            })
          }

          /*
           * Checks all the Time Entries under issue_id
           */
          function toggleTimeEntriesSelection(entryname) {
            $$('.issue-time-entry-' + entryname).each(function(ele) {
              toggleIssuesSelection(ele);
            });
          }

        </script>
      <% else %>
        <%# Default to :project %>
        <h3><%= h entryname -%> (<%= h number_with_precision(@total[entryname], :precision => @precision) %> <%= h(l(:field_hours)) -%>) <%= showing_users(entry[:users]) %></h3> 
        <%= render :partial => 'timesheet_group', :locals => {:entry => entry, :name => entryname, :total => @total[entryname] } %>

      <% end
      end # each
    end # length
  end # form_tag
-%>

<% content_for(:header_tags) do %>
  <%= javascript_include_tag 'context_menu' %>
  <%= stylesheet_link_tag 'context_menu' %>
  <%= stylesheet_link_tag 'timesheet.css', :plugin => 'redmine_timesheet_plugin', :media => 'all' %>
  <%= stylesheet_link_tag 'timesheet-print.css', :plugin => 'redmine_timesheet_plugin', :media => 'print' %>
  <%= javascript_include_tag 'timesheet.js', :plugin => 'redmine_timesheet_plugin' %>
  <%= call_hook(:plugin_timesheet_views_timesheets_report_header_tags, { :timesheet => @timesheet }) %>
<% end %>

<%= context_menu time_entries_context_menu_path %>

<%# TODO: Typo on hook %>
<%= call_hook(:plugin_timesheet_view_timesheets_report_bottom, { :timesheet => @timesheet }) %>
<%= call_hook(:plugin_timesheet_views_timesheets_report_bottom, { :timesheet => @timesheet }) %>
